package com.eastcom.providor.service.impl;

import java.util.List;
import java.util.Map;

import com.eastcom.bm.atom.Atom_MsgSub;
import com.eastcom.providor.dao.IMsgSubDao;
import com.eastcom.providor.service.BaseService;
import com.eastcom.providor.service.IMsgSubService;

public class MsgSubService extends BaseService implements IMsgSubService {

	private IMsgSubDao subDao;
	
	public List<Atom_MsgSub> selectAllMsgSub(int type) {
		List<Atom_MsgSub> ret=null;
		try {
			ret=subDao.selectAllMsgSub(type);
		} catch (Exception e) {
			e.printStackTrace();
			log.error("MsgSubService.selectAllMsgSub exception for:"+e.getMessage());
		}
		return ret;
	}

	public boolean addMsgSub(int type, String email) {
		Atom_MsgSub sub=new Atom_MsgSub();
		sub.setSubType(type);
		sub.setEmail(email);
		try {
			subDao.addMsgSubDao(sub);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			log.error("MsgSubService.addMsgSub exception for:"+e.getMessage());
		}
		return false;
	}

	public boolean deleteMsgSub(List<String> ids) {
		try {
			subDao.deleteMsgSubDao(ids);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			log.error("MsgSubService.deleteMsgSub exception for:"+e.getMessage());
		}
		return false;
	}

	public boolean update(Map beanMap) {
		String id=(String)beanMap.get("id");
		String dataset_id=(String)beanMap.get("dataset_id");
		int type=Integer.parseInt(beanMap.get("type").toString());
		String email=(String)beanMap.get("email");
		Atom_MsgSub sub=new Atom_MsgSub();
		sub.setId(id);
		sub.setDataset_id(dataset_id);
		sub.setSubType(type);
		sub.setEmail(email);
		try {
			this.subDao.update(sub);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			log.error("MsgSubService.update exception for:"+e.getMessage());
		}
		return false;
	}
	
	public IMsgSubDao getSubDao() {
		return subDao;
	}

	public void setSubDao(IMsgSubDao subDao) {
		this.subDao = subDao;
	}
}
